package com.pureut.storage.service.impl;

import com.pureut.storage.domain.order.domain.OrderSupplierManagement;
import com.pureut.storage.dto.OrderSupplierManagementMqDto;
import com.pureut.storage.mapper.OrderSupplierManagementMapper;
import com.pureut.storage.service.OrderSupplierManagementService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 供应商实现层
 */
@RequiredArgsConstructor
@Service
public class OrderSupplierManagementServiceImpl implements OrderSupplierManagementService {

    private final OrderSupplierManagementMapper orderSupplierManagementMapper;

    /**
     * 新增
     * @param mq
     */
    @Override
    public void insertOrderSupplierManagement(OrderSupplierManagementMqDto mq) {
        if (mq.getSupplierNum() != null) {
            OrderSupplierManagement orderSupplierManagement = new OrderSupplierManagement();
            BeanUtils.copyProperties(mq, orderSupplierManagement);
            orderSupplierManagement.setId(mq.getId());
            orderSupplierManagement.setTenantId(mq.getTenantId());
            orderSupplierManagementMapper.insert(orderSupplierManagement);
        }
    }

    /**
     * 修改
     * @param mq
     */
    @Override
    public void updateOrderSupplierManagement(OrderSupplierManagementMqDto mq) {
        OrderSupplierManagement orderSupplierManagement = orderSupplierManagementMapper.selectById(mq.getId());
        BeanUtils.copyProperties(mq,orderSupplierManagement);
        orderSupplierManagementMapper.updateById(orderSupplierManagement);
    }

    /**
     * 删除
     * @param mq
     */
    @Override
    public void deleteOrderSupplierManagement(OrderSupplierManagementMqDto mq) {
        List<String> idList = Arrays.asList(mq.getIdStr().split(","));
        orderSupplierManagementMapper.deleteData(idList);
    }
}
